package ZuoYe03_YouCanFangFa2_0507;

import java.util.Scanner;

import com.CustManager;

/**
 * 3：学士后班级有班级Class名称，班主任teacher姓名，开班日期date等属性， 学生信息用数组表示。用方法模拟 新生加入班级join a
 * class， 以及获得班级人数class people的方法。
 * 
 * @author zhaoyang
 *
 */
public class Class {
	String className;
	String teachName;
	String classDate;
	String[] student = new String[30];

	public boolean findStudent(String studentName) {
		for (int i = 0; i < student.length; i++) {
			if (studentName.equals(student[i])) {
				return true;
			}
		}
		return false;
	}

	public void joinClass(String studentName) {
		if (findStudent(studentName)) {
			System.out.println("学生姓名不能重复!");
			return;
		}
		for (int i = 0; i < student.length; i++) {
			if (student[i] == null) {
				student[i] = studentName;
				System.out.println("添加成功!");
				return;
			}
		}
		System.out.println("添加失败!");

	}

	public int getClassPeople() {
		int count = 0;
		for (int i = 0; i < student.length; i++) {
			if (student[i] != null) {
				count++;
			}
		}
		return count;

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Class p = new Class();
		while (true) {
			System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>");
			System.out.println("1、新增学生姓名\n2、显示学生人数\n0、退出程序");
			System.out.println("请输入功能选择：");
			Scanner input = new Scanner(System.in);
			int num = input.nextInt();

			if (num == 1) {
				System.out.print("请输入新增的学生姓名：");
				String studentName = input.next();
				p.joinClass(studentName);

			} else if (num == 2) {
				System.out.println("目前学生人数是：" + p.getClassPeople() + "人。");

			} else if (num == 0) {
				System.out.println("程序退出,谢谢使用！");
				break;
			}
		}

	}
}
